/*
 * @Author: C.
 * @Date: 2024-07-30 22:01:16
 */
import { onMounted, Ref, ref, reactive, unref } from "vue";
import { getElSize } from "../utils";
import { IPositon } from "../types";
export function useParent(containerRef: Ref<HTMLElement | undefined>) {
  const parentPosition = reactive<IPositon>({
    w: 0,
    h: 0,
    x: 0,
    y: 0
  });
  onMounted(() => {
    if (containerRef.value && containerRef.value.parentElement) {
      const { width, height, x, y } = getElSize(
        containerRef.value.parentElement
      );
      parentPosition.w = width;
      parentPosition.h = height;
      parentPosition.x = x;
      parentPosition.y = y;
    }
  });
  return {
    parentPosition
  };
}
